//
//  RebateTableViewCell.swift
//  kxf
//
//  Created by Mac on 2024/3/12.
//

import Foundation
import UIKit

class RebateTableViewCell: UITableViewCell {
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.backgroundColor = .COLOR_LIGHT_GREY
        self.selectionStyle = .none
        
        initUI()
    }
    lazy var whiteView : UIView = {
        let vi = UIView()
        vi.layer.cornerRadius = kFitWidth(10)
        vi.clipsToBounds = true
        vi.backgroundColor = .white
        vi.isUserInteractionEnabled = true
        
        return vi
    }()
    lazy var payTypeIconImgView : UIImageView = {
        let img = UIImageView()
        img.setImgLocal(imgName: "market_mange_icon")
        
        return img
    }()
    lazy var mercNameLabel : UILabel = {
        let lab = UILabel()
        lab.textColor = .black
        lab.font = .systemFont(ofSize: 16, weight: .medium)
        lab.adjustsFontSizeToFitWidth = true
        
        return lab
    }()
    lazy var timeLabel : UILabel = {
        let lab = UILabel()
        lab.textColor = .COLOR_TEXT_BLACK666
        lab.font = .systemFont(ofSize: 12, weight: .regular)
        
        return lab
    }()
    lazy var moneyLabel : UILabel = {
        let lab = UILabel()
        lab.textColor = .black
        lab.font = .systemFont(ofSize: 18, weight: .bold)
        
        return lab
    }()
    lazy var rebateLabel : UILabel = {
        let lab = UILabel()
        lab.textColor = .COLOR_TEXT_BLACK666
        lab.font = .systemFont(ofSize: 12, weight: .regular)
        
        return lab
    }()
    lazy var lineView : UIView = {
        let vi = UIView()
        vi.backgroundColor = .COLOR_LIGHT_GREY
        return vi
    }()
    lazy var settleTypeLabel : UILabel = {
        let lab = UILabel()
        lab.textColor = .COLOR_TEXT_BLACK999
        lab.font = .systemFont(ofSize: 12, weight: .regular)
        
        return lab
    }()
}

extension RebateTableViewCell{
    func updateUI(dict:NSDictionary) {
        mercNameLabel.text = "\(dict["remark"]as? String ?? "")"
        timeLabel.text = "时间：\(Date().timestampToDate(timestamp: TimeInterval((dict["createTime"]as? Int ?? 0)/1000),format: "yyyy-MM-dd"))"
        moneyLabel.text = "¥ \(dict["reserveOne"]as? String ?? "0.00")"
        rebateLabel.text = "收益：¥\(dict["amount"]as? Double ?? 0.00)"
        
        if dict["secService"]as? Int ?? 0 == 1{
            settleTypeLabel.text = "结算方式：合并到账"
        }else{
            settleTypeLabel.text = "结算方式：实时到账"
        }
        
    }
}
extension RebateTableViewCell{
    func initUI() {
        contentView.addSubview(whiteView)
        whiteView.addSubview(payTypeIconImgView)
        whiteView.addSubview(mercNameLabel)
        whiteView.addSubview(timeLabel)
        whiteView.addSubview(moneyLabel)
        whiteView.addSubview(rebateLabel)
        whiteView.addSubview(settleTypeLabel)
        whiteView.addSubview(lineView)
        
        setConstrait()
    }
    func setConstrait() {
        whiteView.snp.makeConstraints { make in
            make.centerX.lessThanOrEqualToSuperview()
            make.width.equalTo(kFitWidth(343))
            make.height.equalTo(kFitWidth(132))
            make.top.equalTo(kFitWidth(10))
        }
        payTypeIconImgView.snp.makeConstraints { make in
            make.left.top.equalTo(kFitWidth(12))
            make.width.height.equalTo(kFitWidth(22))
        }
        mercNameLabel.snp.makeConstraints { make in
            make.left.equalTo(kFitWidth(41))
            make.top.equalTo(kFitWidth(12))
            make.height.equalTo(kFitWidth(22))
            make.right.equalTo(kFitWidth(-20))
        }
        timeLabel.snp.makeConstraints { make in
            make.left.equalTo(kFitWidth(12))
            make.top.equalTo(kFitWidth(46))
            make.height.equalTo(kFitWidth(17))
        }
        moneyLabel.snp.makeConstraints { make in
            make.right.equalTo(kFitWidth(-12))
            make.top.equalTo(kFitWidth(32))
            make.height.equalTo(kFitWidth(23))
        }
        rebateLabel.snp.makeConstraints { make in
            make.left.equalTo(timeLabel)
            make.top.equalTo(kFitWidth(75))
            make.height.equalTo(kFitWidth(17))
        }
        settleTypeLabel.snp.makeConstraints { make in
            make.left.equalTo(timeLabel)
            make.bottom.equalToSuperview()
            make.height.equalTo(kFitWidth(32))
        }
        lineView.snp.makeConstraints { make in
            make.left.width.equalToSuperview()
            make.bottom.equalTo(kFitWidth(-32))
            make.height.equalTo(kFitWidth(0.5))
        }
    }
}
